﻿using Microsoft.AspNetCore.Mvc;
using TR.AppService.AppService.BS;
using TR.Domain.Entity.BsItemType;
using TR.Domain.Entity;
using TR.Domain.Repository.Sys_EncodeRepository;
using TR.Domain.Repository.BSType;
using TR.AppService.Dto.BSDto;
using TR.AppService.Dto;
using TR.Domain.Repository.BS_Item_TypeRepository;

namespace TR.WebApi.Controllers.BS
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class ItemTypeController : ControllerBase
    {
        private readonly IBsItemTypeService bsItemTypeService;
        public ItemTypeController(IBsItemTypeService bsItemTypeService)
        {
            this.bsItemTypeService = bsItemTypeService;
        }
        /// <summary>
        /// 分页
        /// </summary>
        /// <param name="pageSize"></param>
        /// <param name="currentPage"></param>
        /// <param name="str"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<DtoFenYe<bs_Item_Type>> bs_Itemtype_FenYe(int pageSize, int currentPage,  [FromQuery] BSFenYeTjDto bit = null)
        {           
            return await bsItemTypeService.bs_ItemType_FenYe(pageSize, currentPage, null, null, bit);
        }
        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="ItemTypeAdd"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<bool> ItemTypeAdd(AddItemTypeDto addItemtypeDto)
        {
            ControllerContext.HttpContext.Response.Headers.Add("Access-Control-Allow-Origin", "*");
            Console.WriteLine("ItemTypeAdd--->");
            return await bsItemTypeService.ItemtypeAdd(addItemtypeDto);
        }
        /// <summary> 
        /// 逻辑删除
        /// </summary>
        /// <param name="item_type_code"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<bool> ItemtypeUDelect(string item_type_code)
        {
            ControllerContext.HttpContext.Response.Headers.Add("Access-Control-Allow-Origin", "*");
            Console.WriteLine("ItemtypeUDelect--->");
            return await bsItemTypeService.ItemtypeUDelect(item_type_code);
        }
        /// <summary>
        /// 查询id
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<bs_Item_Type> ItemTypeSelectid(int id)
        {
            ControllerContext.HttpContext.Response.Headers.Add("Access-Control-Allow-Origin", "*");
            Console.WriteLine("ItemTypeSelectid--->");
            return bsItemTypeService.ItemTypeSelectid(id);
        }
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="usd"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<bool> ItemTypeUpdate(UpdateItemTypeDto usd)
        {
            ControllerContext.HttpContext.Response.Headers.Add("Access-Control-Allow-Origin", "*");
            Console.WriteLine("ItemTypeUpdate--->");
            return await bsItemTypeService.ItemTypeUpdate(usd);
        }
    }   
}
